package org.example;

import org.example.T.Child;
import org.example.T.Father;
import org.example.T.Mother;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello world!
 *
 */
public class App {
    public static void main( String[] args )
    {
        //这个就是应用程序上下文ClassPathXmlApplicationContext，就是这个来帮我们处理依赖关系
        //就是配置文件的三个bean，创建ioc容器，导入bean，并初始化bean
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
        //这里的getBean就是配置文件的bean里的id
        Child child =(Child) context.getBean("child");
        Child child1 =(Child) context.getBean("child");
        //证明bean里面就只有一个child，==是比较地址,这里是加了一个多列的标签。
        if (child == child1){
            System.out.println("child=child1");
        }else {
            System.out.println("child !=child1");
        }
        System.out.println(child);
        Father father = (Father) context.getBean("father");
        Father father1 = (Father) context.getBean("father");
        if (father == father1){
            System.out.println("father = father1");
        }else {
            System.out.println("father != father1");
        }
        Mother mother = (Mother) context.getBean("mather");
        if (mother.cook()){
            child.eat();
            mother.eat();
            father.eat();
        }
    }
}
